<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="easyui-panel" title="${title}" style="width:100%;max-width:400px;padding:30px 60px;">
    <form id="category_from" method="post" action="#">
        <input type="hidden" name="id" value="${categorys.data.id}">
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="name" value="${categorys.data.name}" style="width:100%" data-options="label:'分类名称:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="orderBy" value="${categorys.data.orderBy}" style="width:100%" data-options="label:'排序:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="keywords" value="${categorys.data.keywords}" style="width:100%" data-options="label:'关键字:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="description" value="${categorys.data.description}" style="width:100%" data-options="label:'描述:',required:true">
        </div>
    </form>
    <div style="text-align:center;padding:5px 0">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:80px">提交</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">清空</a>
    </div>
</div>
<script>
    function submitForm() {
        var subUrl = "${pageContext.request.contextPath}/category/datapost";
        var b = $("#category_from").form('validate');
        if(b){
            var JsonDate =  $.serializeObject($('#category_from'));
            $.ajax({
                type: "POST",
                cache:false,
                url: subUrl,
                data:JSON.stringify(JsonDate),
                contentType : 'application/json',
                dataType:"json",
                success: function(data){
                    console.info("------------------------");
                    console.info(data);
                    if(data.errCode == 0){
                        $('#category_tree').tree("reload");
                    }else{
                        $.messager.alert('警告','操作失败');
                    }
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    console.info(XMLHttpRequest);
                    console.info(textStatus);
                    console.info(errorThrown);
                    $.messager.alert('警告','error操作失败');
                }
            });
        }

    }
    function clearForm() {
        $('#category_from').form('clear');
    }
</script>
